# Copyright 2020 Makani Technologies LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Automatically generated controllers.

This file was generated by: analysis/control/crosswind.py.
"""

from makani.control import control_types as m


def GetControllers(wing_serial):
  """Returns control gain matrices for any kite serial number."""
  if wing_serial == m.kWingSerial01:
    airspeed_table = (
        [30.0, 60.0, 90.0]
    )
    flap_offsets = (
        [-0.209, -0.209, 0.0, 0.0, 0.009, 0.009, -0.005, 0.017]
    )
    longitudinal_gains_min_airspeed = (
        [[0.005, 0.034, -0.716, -0.333, 0.311],
         [-9.239, -68.061, 1361.046, 641.777, -589.016]]
    )
    longitudinal_gains_nominal_airspeed = (
        [[0.014, 0.013, -0.509, -0.168, 0.316],
         [-6.676, -6.529, 234.939, 80.993, -147.915]]
    )
    longitudinal_gains_max_airspeed = (
        [[0.009, 0.007, -0.401, -0.136, 0.316],
         [-1.965, -1.585, 79.966, 28.908, -65.259]]
    )
    lateral_gains_min_airspeed = (
        [[1.477, -1.589, -0.434, 0.296, -0.75, 0.329],
         [0.224, 1.045, 0.065, -0.554, -0.429, -0.282],
         [-18215.48, -42217.142, -2192.239, 28689.136, 25162.461, 12500.22]]
    )
    lateral_gains_nominal_airspeed = (
        [[1.063, -1.48, -0.234, 0.195, -0.772, 0.317],
         [0.38, 1.123, 0.036, -0.386, -0.609, -0.376],
         [-6604.64, -11507.484, -340.275, 5156.255, 9047.472, 4427.592]]
    )
    lateral_gains_max_airspeed = (
        [[0.982, -1.395, -0.198, 0.149, -0.786, 0.309],
         [0.27, 1.107, 0.027, -0.287, -0.613, -0.391],
         [-2275.783, -4917.11, -119.56, 1730.983, 4062.059, 2033.279]]
    )
    B_flaps_to_pqr_min_airspeed = (  # pylint: disable=invalid-name
        [[-5.587, 0.004, 0.11], [-0.03, -6.079, -0.026], [0.243, 0.006, -1.06]]
    )

  elif wing_serial == m.kWingSerial04Hover:
    airspeed_table = (
        [30.0, 60.0, 90.0]
    )
    flap_offsets = (
        [-0.211, -0.211, 0.0, 0.0, 0.011, 0.011, 0.005, 0.008]
    )
    longitudinal_gains_min_airspeed = (
        [[-0.002, 0.033, -0.73, -0.357, 0.311],
         [4.546, -64.827, 1390.055, 688.515, -589.338]]
    )
    longitudinal_gains_nominal_airspeed = (
        [[0.011, 0.014, -0.548, -0.182, 0.316],
         [-5.284, -6.728, 254.985, 87.909, -148.241]]
    )
    longitudinal_gains_max_airspeed = (
        [[0.008, 0.008, -0.441, -0.144, 0.316],
         [-1.676, -1.659, 89.199, 30.631, -65.417]]
    )
    lateral_gains_min_airspeed = (
        [[1.44, -1.617, -0.409, 0.296, -0.743, 0.333],
         [0.254, 1.044, 0.06, -0.551, -0.432, -0.277],
         [-19794.459, -43094.943, -1997.427, 28857.76, 25564.594, 12475.401]]
    )
    lateral_gains_nominal_airspeed = (
        [[1.036, -1.502, -0.224, 0.194, -0.768, 0.32],
         [0.433, 1.136, 0.033, -0.39, -0.614, -0.374],
         [-7324.836, -11932.75, -305.45, 5272.765, 9170.382, 4461.79]]
    )
    lateral_gains_max_airspeed = (
        [[0.956, -1.415, -0.192, 0.148, -0.783, 0.311],
         [0.323, 1.123, 0.025, -0.291, -0.617, -0.389],
         [-2588.374, -5128.587, -109.03, 1771.109, 4110.266, 2055.664]]
    )
    B_flaps_to_pqr_min_airspeed = (  # pylint: disable=invalid-name
        [[-5.92, -0.002, 0.128],
         [-0.027, -5.506, -0.024],
         [0.252, 0.005, -1.083]]
    )

  elif wing_serial == m.kWingSerial04Crosswind:
    airspeed_table = (
        [30.0, 60.0, 90.0]
    )
    flap_offsets = (
        [-0.206, -0.206, 0.0, 0.0, 0.006, 0.006, 0.004, 0.009]
    )
    longitudinal_gains_min_airspeed = (
        [[-0.004, 0.033, -0.743, -0.369, 0.311],
         [6.879, -65.952, 1416.656, 711.871, -589.814]]
    )
    longitudinal_gains_nominal_airspeed = (
        [[0.011, 0.014, -0.562, -0.187, 0.316],
         [-5.048, -6.949, 262.084, 90.532, -148.346]]
    )
    longitudinal_gains_max_airspeed = (
        [[0.008, 0.008, -0.451, -0.146, 0.316],
         [-1.652, -1.714, 91.319, 31.157, -65.442]]
    )
    lateral_gains_min_airspeed = (
        [[1.473, -1.597, -0.421, 0.294, -0.746, 0.331],
         [0.237, 1.043, 0.061, -0.559, -0.431, -0.28],
         [-19140.086, -42177.964, -1957.253, 29074.862, 25405.542, 12435.884]]
    )
    lateral_gains_nominal_airspeed = (
        [[1.063, -1.486, -0.228, 0.193, -0.769, 0.319],
         [0.403, 1.124, 0.033, -0.391, -0.613, -0.374],
         [-6972.675, -11547.427, -303.445, 5257.572, 9146.686, 4416.334]]
    )
    lateral_gains_max_airspeed = (
        [[0.983, -1.401, -0.195, 0.148, -0.782, 0.311],
         [0.294, 1.108, 0.025, -0.291, -0.617, -0.389],
         [-2439.793, -4940.323, -108.619, 1761.451, 4108.271, 2029.644]]
    )
    B_flaps_to_pqr_min_airspeed = (  # pylint: disable=invalid-name
        [[-5.721, -0.001, 0.125],
         [-0.028, -5.332, -0.022],
         [0.243, 0.005, -1.048]]
    )

  elif wing_serial == m.kWingSerial05Hover:
    airspeed_table = (
        [30.0, 60.0, 90.0]
    )
    flap_offsets = (
        [-0.204, -0.204, 0.0, 0.0, 0.004, 0.004, 0.004, 0.007]
    )
    longitudinal_gains_min_airspeed = (
        [[-0.003, 0.033, -0.732, -0.353, 0.311],
         [5.756, -65.225, 1393.028, 681.0, -589.458]]
    )
    longitudinal_gains_nominal_airspeed = (
        [[0.011, 0.014, -0.552, -0.181, 0.316],
         [-5.157, -6.823, 257.066, 87.46, -148.262]]
    )
    longitudinal_gains_max_airspeed = (
        [[0.008, 0.008, -0.445, -0.143, 0.316],
         [-1.655, -1.692, 90.117, 30.558, -65.423]]
    )
    lateral_gains_min_airspeed = (
        [[1.438, -1.611, -0.401, 0.289, -0.743, 0.333],
         [0.257, 1.041, 0.058, -0.542, -0.432, -0.278],
         [-20011.52, -42735.847, -1914.014, 28358.023, 25584.42, 12448.614]]
    )
    lateral_gains_nominal_airspeed = (
        [[1.043, -1.502, -0.221, 0.191, -0.767, 0.32],
         [0.428, 1.13, 0.032, -0.383, -0.614, -0.374],
         [-7288.823, -11800.514, -296.679, 5172.453, 9185.489, 4445.84]]
    )
    lateral_gains_max_airspeed = (
        [[0.965, -1.415, -0.191, 0.146, -0.782, 0.311],
         [0.318, 1.117, 0.024, -0.286, -0.617, -0.389],
         [-2567.285, -5064.437, -106.454, 1742.745, 4117.291, 2047.19]]
    )
    B_flaps_to_pqr_min_airspeed = (  # pylint: disable=invalid-name
        [[-6.043, -0.014, 0.134],
         [-0.027, -5.618, -0.024],
         [0.257, 0.005, -1.105]]
    )

  elif wing_serial == m.kWingSerial05Crosswind:
    airspeed_table = (
        [30.0, 60.0, 90.0]
    )
    flap_offsets = (
        [-0.198, -0.198, 0.0, 0.0, -0.002, -0.002, 0.003, 0.009]
    )
    longitudinal_gains_min_airspeed = (
        [[-0.004, 0.033, -0.744, -0.364, 0.311],
         [7.876, -66.499, 1418.317, 702.426, -589.905]]
    )
    longitudinal_gains_nominal_airspeed = (
        [[0.01, 0.014, -0.565, -0.186, 0.316],
         [-4.942, -7.054, 263.793, 89.867, -148.357]]
    )
    longitudinal_gains_max_airspeed = (
        [[0.008, 0.008, -0.454, -0.145, 0.316],
         [-1.635, -1.75, 92.08, 31.033, -65.443]]
    )
    lateral_gains_min_airspeed = (
        [[1.47, -1.591, -0.412, 0.286, -0.746, 0.331],
         [0.24, 1.039, 0.059, -0.549, -0.431, -0.281],
         [-19344.869, -41752.487, -1867.667, 28478.098, 25425.604, 12404.153]]
    )
    lateral_gains_nominal_airspeed = (
        [[1.07, -1.485, -0.226, 0.189, -0.768, 0.32],
         [0.397, 1.117, 0.033, -0.383, -0.613, -0.374],
         [-6919.209, -11394.187, -294.167, 5138.956, 9160.95, 4397.605]]
    )
    lateral_gains_max_airspeed = (
        [[0.993, -1.401, -0.193, 0.145, -0.782, 0.312],
         [0.287, 1.101, 0.025, -0.285, -0.618, -0.389],
         [-2410.981, -4866.463, -105.87, 1728.008, 4114.679, 2019.74]]
    )
    B_flaps_to_pqr_min_airspeed = (  # pylint: disable=invalid-name
        [[-5.857, -0.012, 0.131],
         [-0.03, -5.457, -0.022],
         [0.249, 0.005, -1.072]]
    )

  elif wing_serial == m.kWingSerial06Hover:
    airspeed_table = (
        [30.0, 60.0, 90.0]
    )
    flap_offsets = (
        [-0.208, -0.208, 0.0, 0.0, 0.008, 0.008, 0.006, 0.007]
    )
    longitudinal_gains_min_airspeed = (
        [[-0.003, 0.032, -0.731, -0.358, 0.311],
         [6.453, -64.539, 1392.121, 689.765, -589.371]]
    )
    longitudinal_gains_nominal_airspeed = (
        [[0.011, 0.014, -0.553, -0.183, 0.316],
         [-5.088, -6.779, 257.684, 88.435, -148.279]]
    )
    longitudinal_gains_max_airspeed = (
        [[0.008, 0.008, -0.447, -0.144, 0.316],
         [-1.637, -1.678, 90.467, 30.782, -65.435]]
    )
    lateral_gains_min_airspeed = (
        [[1.438, -1.616, -0.408, 0.296, -0.742, 0.333],
         [0.255, 1.044, 0.059, -0.552, -0.432, -0.277],
         [-19907.663, -43108.523, -1968.711, 28927.246, 25591.178, 12468.239]]
    )
    lateral_gains_nominal_airspeed = (
        [[1.038, -1.503, -0.224, 0.194, -0.768, 0.32],
         [0.435, 1.136, 0.033, -0.391, -0.614, -0.374],
         [-7364.944, -11935.606, -300.999, 5287.24, 9178.769, 4462.368]]
    )
    lateral_gains_max_airspeed = (
        [[0.958, -1.416, -0.192, 0.148, -0.783, 0.311],
         [0.325, 1.123, 0.024, -0.291, -0.617, -0.389],
         [-2605.535, -5129.038, -107.775, 1775.087, 4114.053, 2056.295]]
    )
    B_flaps_to_pqr_min_airspeed = (  # pylint: disable=invalid-name
        [[-5.912, -0.009, 0.13],
         [-0.025, -5.494, -0.024],
         [0.252, 0.005, -1.081]]
    )

  elif wing_serial == m.kWingSerial06Crosswind:
    airspeed_table = (
        [30.0, 60.0, 90.0]
    )
    flap_offsets = (
        [-0.203, -0.203, 0.0, 0.0, 0.003, 0.003, 0.004, 0.008]
    )
    longitudinal_gains_min_airspeed = (
        [[-0.004, 0.033, -0.743, -0.369, 0.311],
         [8.412, -65.841, 1417.073, 711.786, -589.819]]
    )
    longitudinal_gains_nominal_airspeed = (
        [[0.01, 0.014, -0.566, -0.188, 0.316],
         [-4.888, -7.008, 264.204, 90.884, -148.372]]
    )
    longitudinal_gains_max_airspeed = (
        [[0.008, 0.008, -0.455, -0.146, 0.316],
         [-1.62, -1.735, 92.313, 31.262, -65.454]]
    )
    lateral_gains_min_airspeed = (
        [[1.471, -1.596, -0.42, 0.293, -0.746, 0.331],
         [0.239, 1.043, 0.06, -0.559, -0.431, -0.28],
         [-19231.343, -42149.313, -1926.317, 29079.197, 25426.856, 12427.585]]
    )
    lateral_gains_nominal_airspeed = (
        [[1.065, -1.487, -0.228, 0.193, -0.769, 0.319],
         [0.404, 1.123, 0.033, -0.391, -0.613, -0.374],
         [-6992.628, -11534.142, -299.093, 5258.12, 9152.573, 4415.616]]
    )
    lateral_gains_max_airspeed = (
        [[0.986, -1.402, -0.194, 0.148, -0.782, 0.311],
         [0.294, 1.108, 0.025, -0.29, -0.617, -0.389],
         [-2447.327, -4933.324, -107.393, 1761.417, 4110.821, 2029.552]]
    )
    B_flaps_to_pqr_min_airspeed = (  # pylint: disable=invalid-name
        [[-5.725, -0.008, 0.128],
         [-0.027, -5.331, -0.022],
         [0.243, 0.005, -1.048]]
    )

  elif wing_serial == m.kWingSerial07Hover:
    airspeed_table = (
        [30.0, 60.0, 90.0]
    )
    flap_offsets = (
        [-0.211, -0.211, 0.0, 0.0, 0.011, 0.011, 0.005, 0.008]
    )
    longitudinal_gains_min_airspeed = (
        [[-0.002, 0.033, -0.73, -0.357, 0.311],
         [4.546, -64.827, 1390.055, 688.515, -589.338]]
    )
    longitudinal_gains_nominal_airspeed = (
        [[0.011, 0.014, -0.548, -0.182, 0.316],
         [-5.284, -6.728, 254.985, 87.909, -148.241]]
    )
    longitudinal_gains_max_airspeed = (
        [[0.008, 0.008, -0.441, -0.144, 0.316],
         [-1.676, -1.659, 89.199, 30.631, -65.417]]
    )
    lateral_gains_min_airspeed = (
        [[1.44, -1.617, -0.409, 0.296, -0.743, 0.333],
         [0.254, 1.044, 0.06, -0.551, -0.432, -0.277],
         [-19794.459, -43094.943, -1997.427, 28857.76, 25564.594, 12475.401]]
    )
    lateral_gains_nominal_airspeed = (
        [[1.036, -1.502, -0.224, 0.194, -0.768, 0.32],
         [0.433, 1.136, 0.033, -0.39, -0.614, -0.374],
         [-7324.836, -11932.75, -305.45, 5272.765, 9170.382, 4461.79]]
    )
    lateral_gains_max_airspeed = (
        [[0.956, -1.415, -0.192, 0.148, -0.783, 0.311],
         [0.323, 1.123, 0.025, -0.291, -0.617, -0.389],
         [-2588.374, -5128.587, -109.03, 1771.109, 4110.266, 2055.664]]
    )
    B_flaps_to_pqr_min_airspeed = (  # pylint: disable=invalid-name
        [[-5.92, -0.002, 0.128],
         [-0.027, -5.506, -0.024],
         [0.252, 0.005, -1.083]]
    )

  elif wing_serial == m.kWingSerial07Crosswind:
    airspeed_table = (
        [30.0, 60.0, 90.0]
    )
    flap_offsets = (
        [-0.206, -0.206, 0.0, 0.0, 0.006, 0.006, 0.004, 0.009]
    )
    longitudinal_gains_min_airspeed = (
        [[-0.004, 0.033, -0.743, -0.369, 0.311],
         [6.879, -65.952, 1416.656, 711.871, -589.814]]
    )
    longitudinal_gains_nominal_airspeed = (
        [[0.011, 0.014, -0.562, -0.187, 0.316],
         [-5.048, -6.949, 262.084, 90.532, -148.346]]
    )
    longitudinal_gains_max_airspeed = (
        [[0.008, 0.008, -0.451, -0.146, 0.316],
         [-1.652, -1.714, 91.319, 31.157, -65.442]]
    )
    lateral_gains_min_airspeed = (
        [[1.473, -1.597, -0.421, 0.294, -0.746, 0.331],
         [0.237, 1.043, 0.061, -0.559, -0.431, -0.28],
         [-19140.086, -42177.964, -1957.253, 29074.862, 25405.542, 12435.884]]
    )
    lateral_gains_nominal_airspeed = (
        [[1.063, -1.486, -0.228, 0.193, -0.769, 0.319],
         [0.403, 1.124, 0.033, -0.391, -0.613, -0.374],
         [-6972.675, -11547.427, -303.445, 5257.572, 9146.686, 4416.334]]
    )
    lateral_gains_max_airspeed = (
        [[0.983, -1.401, -0.195, 0.148, -0.782, 0.311],
         [0.294, 1.108, 0.025, -0.291, -0.617, -0.389],
         [-2439.793, -4940.323, -108.619, 1761.451, 4108.271, 2029.644]]
    )
    B_flaps_to_pqr_min_airspeed = (  # pylint: disable=invalid-name
        [[-5.721, -0.001, 0.125],
         [-0.028, -5.332, -0.022],
         [0.243, 0.005, -1.048]]
    )

  else:
    assert False, 'wing_serial %d was not recognized' % wing_serial

  return {
      'airspeed_table': (
          airspeed_table),
      'flap_offsets': (
          flap_offsets),
      'longitudinal_gains_min_airspeed': (
          longitudinal_gains_min_airspeed),
      'longitudinal_gains_nominal_airspeed': (
          longitudinal_gains_nominal_airspeed),
      'longitudinal_gains_max_airspeed': (
          longitudinal_gains_max_airspeed),
      'lateral_gains_min_airspeed': (
          lateral_gains_min_airspeed),
      'lateral_gains_nominal_airspeed': (
          lateral_gains_nominal_airspeed),
      'lateral_gains_max_airspeed': (
          lateral_gains_max_airspeed),
      'B_flaps_to_pqr_min_airspeed': (
          B_flaps_to_pqr_min_airspeed),
  }
